package com.authentication.manager;

import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

public class SimpleAuthenticationManager implements AuthenticationManager {
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        if (authentication.getPrincipal()==null||authentication.getCredentials()==null) {
            throw new AuthenticationCredentialsNotFoundException("凭证无效");
        }
        TestingAuthenticationToken result = new TestingAuthenticationToken(authentication.getPrincipal(), null);
        result.setAuthenticated(true);
        return result;

    }
}
